package com.biscuit.page.basicservice.design.flow_limit;

import lombok.Getter;

import java.util.Arrays;

/**
 * @author biscuit
 * @create 2024年07月29日 15:04
 */
@Getter
public enum FlowLimitTypeEnum {

    NOT_FLOW_LIMIT(-1, "不限限流"),
    TOKEN_BUCKET_FLOW_LIMIT(1, "令牌桶限流"),
    LEAKY_BUCKET_FLOW_LIMIT(2, "漏桶算法限流"),
    SLIDING_WINDOW_FLOW_LIMIT(2, "滑动窗口算法限流");

    private final int type;

    private final String desc;

    FlowLimitTypeEnum(int type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public static FlowLimitTypeEnum getEnumByType(int type) {
        return Arrays.stream(FlowLimitTypeEnum.values()).filter(x -> x.getType() == type).findFirst().orElse(null);
    }

}
